package me.xujl;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

import org.apache.camel.Exchange;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;

/**
 * User: xujl
 * Date: 2014/5/21
 */
public class TimeStampProperties {

    private String file;

    private String key;

    public Object process(String body) throws IOException {
        Properties properties = new Properties();
        File f = new File(file);
        if (!f.exists()) {
            FileUtils.touch(f);
        }


        //String d = exchange.getIn().getHeader(value, String.class);
        properties.load(FileUtils.openInputStream(f));

        if (StringUtils.isBlank(body)) {
            return properties.get(key);
        } else {
            properties.setProperty(key, body);
            properties.store(new FileWriter(file), null);
            return null;
        }
    }

    public String getFile() {
        return file;
    }

    public void setFile(String file) {
        this.file = file;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

}
